//
//  SeckillConfirmViewController.m
//  CPICApp
//
//  Created by lizhiwei on 13-3-13.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "SeckillConfirmViewController.h"
#import "RCAlertViewUtil.h"
#import "SeckillResultQueryViewController.h"
#import "AppDelegate.h"
#import "NSString+SBJson.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "OperationLogView.h"
#import <TencentOpenAPI/sdkdef.h>
#import <TencentOpenAPI/TencentOAuthObject.h>
#import "RCCaculateIntegral.h"

@interface SeckillConfirmViewController ()

@end

@implementation SeckillConfirmViewController
@synthesize TableViewCustomerInfo;
@synthesize TableViewGoodsInfo;
@synthesize CustomerAddress;
@synthesize CustomerName;
@synthesize CustomerPhone;
@synthesize GoodsName;
@synthesize GoodsSeckillTime;
@synthesize SmsIdentifyingInfo;
@synthesize txtCustomerAddress;
@synthesize txtCustomerName;
@synthesize txtCustomerPhone;
@synthesize txtGoodsName;
@synthesize txtGoodsSeckillTime;
@synthesize txtSmsIdentifyingInfo;
@synthesize progress;
@synthesize seckillInfo;
@synthesize SeckillSuccessTime;
@synthesize GoodsPrice;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.title = @"秒杀确认";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
	NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"]) 
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"秒杀确认");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"秒杀确认");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"秒杀确认");
        
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
    }
    
    //添加UITableview
    TableViewGoodsInfo = [[UITableView alloc]initWithFrame:CGRectMake(5, 62, self.view.frame.size.width, 200) style:UITableViewStyleGrouped];
	TableViewGoodsInfo.delegate = self;
	TableViewGoodsInfo.dataSource = self;
    
    TableViewGoodsInfo.opaque = NO;
    TableViewGoodsInfo.backgroundView = nil;
    TableViewGoodsInfo.autoresizingMask = UIViewContentModeTop;
    TableViewGoodsInfo.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewGoodsInfo.scrollEnabled=NO;
    TableViewGoodsInfo.backgroundColor=[UIColor clearColor];
	[self.view addSubview:TableViewGoodsInfo];
    
    
    TableViewCustomerInfo = [[UITableView alloc]initWithFrame:CGRectMake(5, 194, self.view.frame.size.width, 250) style:UITableViewStyleGrouped];
	TableViewCustomerInfo.delegate = self;
	TableViewCustomerInfo.dataSource = self;
    
    TableViewCustomerInfo.opaque = NO;
    TableViewCustomerInfo.backgroundView = nil;
    TableViewCustomerInfo.autoresizingMask = UIViewContentModeTop;
    TableViewCustomerInfo.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewCustomerInfo.scrollEnabled=NO;
    TableViewCustomerInfo.backgroundColor=[UIColor clearColor];
	//[self.view addSubview:TableViewCustomerInfo];
    
    //定义“提交”按钮
    UIButton *btnSumbit=[UIButton buttonWithType:UIButtonTypeCustom];
    [btnSumbit setImage:[UIImage imageNamed:@"SaveSet.png"] forState:UIControlStateNormal];
    [btnSumbit setTitle:@"保存设置" forState:UIControlStateNormal];
    btnSumbit.frame=CGRectMake((self.view.frame.size.width-155)/2, 380, 310/2, 68/2);
    [btnSumbit addTarget:self action:@selector(SeckillSumbit) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnSumbit];
    
    UILabel * lbSumbit = [[UILabel alloc]initWithFrame:CGRectMake((self.view.frame.size.width-155)/2, 380,  310/2, 68/2)];
    lbSumbit.text = @"提交";
    lbSumbit.textAlignment = UITextAlignmentCenter;
    lbSumbit.textColor = [UIColor whiteColor];
    lbSumbit.backgroundColor = [UIColor clearColor];
    [self.view addSubview:lbSumbit];
    [lbSumbit release];
    
    //初始化数组
    arrGoods=[[NSMutableArray alloc]initWithObjects:@"商品名称:",@"秒杀成功时间:",@"秒杀成功价格:",@"短信验证信息接收:", nil];
    arrCustomer=[[NSMutableArray alloc]initWithObjects:@"客户名称:",@"联系电话:",@"通讯地址:", nil];
    
    arrGoodsContent=[[NSMutableArray alloc]initWithObjects:@"道路救援服务",@"2013-03-12 13:40",@"13800138000", nil];
    arrCustomerContent=[[NSMutableArray alloc]initWithObjects:@"张三",@"13800138000",@"广州市越秀区东沙角", nil];
    
    self.GoodsName = [self.seckillInfo objectForKey:@"commodityName"];
    self.GoodsSeckillTime =[self.seckillInfo objectForKey:@"successTime"];
    NSLog(@"-------%@",[self.seckillInfo objectForKey:@"secKillPrice"]);
    self.GoodsPrice = [[NSString alloc]initWithFormat:@"%@",[self.seckillInfo objectForKey:@"secKillPrice"]];
    
    NSLog(@"-------%@",self.GoodsPrice);
    CommodityId = [self.seckillInfo objectForKey:@"commodityID"];
    
    NSLog(@"******************%@",CommodityId);
}

-(void) ClickCallOutBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void) SeckillSumbit
{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    myDelegate.bSeckillArea=TRUE;
    
    if (txtSmsIdentifyingInfo.text.length == 0)
    {
        [self justShowMessage:@"短信接收号码不能为空" title:@"提示"];
        return;
    }
    
    NSString * Mobile = txtSmsIdentifyingInfo.text;
    if (![self isValidateMobile:Mobile])
    {
        [self justShowMessage:@"非法的手机号码,请输入正确的手机号码" title:@""];
        return;
    }
    
    /*if (txtCustomerName.text.length == 0) 
    {
        [self justShowMessage:@"客户名不能为空" title:@"提示"];
        return;
    }
    
    if (txtCustomerPhone.text.length == 0) 
    {
        [self justShowMessage:@"手机号码不能为空" title:@"提示"];
        return;
    }
    
    if (txtCustomerAddress.text.length == 0) 
    {
        [self justShowMessage:@"客户联系地址不能为空" title:@"提示"];
        return;
    }*/
    UIAlertView *myalert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"目前太保移动终端'礼品秒杀功能'仅面向通讯地址为深圳市的车主,非深圳市地区暂未开通" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    myalert.tag=1004;
    [myalert show];
    [myalert release];
}

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch(alert.tag)
    {
        case 111:
            if (buttonIndex == 0)
                //默认cancelButtonIndex = 0，每个按钮index可设
            {
                SeckillResultQueryView = [[SeckillResultQueryViewController alloc]init];
                [[AppDelegate app].unc pushViewController:SeckillResultQueryView animated:YES];
                [SeckillResultQueryView release];
            }
            else if(buttonIndex ==1)
            {
                strShareContent=@"秒杀信息秒杀信息秒杀信息秒杀信息";
                isContent=YES;
                isImage=NO;
                [self shareSina];
            }
            else if(buttonIndex == 2)
            {
                strShareContent=@"秒杀信息秒杀信息秒杀信息秒杀信息";
                isContent=YES;
                isImage=NO;
                [self shareQQ];
            }
            break;
        case 1004:
                [self setSeckillConfirmRequest];
            break;
        case 1005:
            if (buttonIndex == 1)
            {
                // post image status
                
                SinaWeibo *sinaweibo = [self sinaweibo];
                
                [sinaweibo requestWithURL:@"statuses/upload.json"
                                   params:[NSMutableDictionary dictionaryWithObjectsAndKeys:
                                           postImageStatusText, @"status",
                                           imageDown, @"pic", nil]
                               httpMethod:@"POST"
                                 delegate:self];
                    
            }
            break;
        case 1006:
         if (buttonIndex == 1)
         {
             // post status
             NSLog(@"秒杀信息%@",postStatusText);
             SinaWeibo *sinaweibo = [self sinaweibo];
             [sinaweibo requestWithURL:@"statuses/update.json"
                                params:[NSMutableDictionary dictionaryWithObjectsAndKeys:
                                        postStatusText, @"status",
                                        nil]
                            httpMethod:@"POST"
                              delegate:self];
                    
        }
            break;
        case 1007:
             if (buttonIndex == 1)
                {
                    if (isImage==YES && isContent==NO) {
                        TCAddShareDic *params = [TCAddShareDic dictionary];
                        params.paramTitle = @"太平洋保险- 秒杀信息分享";
                        strInsuranceTitle = [[NSString alloc] initWithFormat:@"我秒杀成功啦!!!以%@元秒杀到%@,天天有惊喜《车E服》http://www.cpic.com.cn/cx/sz/ydkhd/index.shtml",self.GoodsPrice,self.GoodsName];
                        params.paramComment = strInsuranceTitle;
                        //            params.paramSummary =  @"中国太平洋保险成立于1991年5月13日，总部设在上海，成功在A股和H股上市，旗下拥有太平洋寿险、太平洋产险、太平洋资产管理公司和长江养老保险等专业子公司，保持持续领先的市场地位。";
                        //            params.paramImages = @"http://img1.gtimg.com/tech/pics/hv1/95/153/847/55115285.jpg";
                        
                        if ([ImgUrl isKindOfClass:[NSString class]]==YES) {
                            if (ImgUrl.length!=0) {
                                params.paramImages=ImgUrl;
                            }
                        }
                        else
                        {
                            [self justShowMessage:@"图片地址无效" title:@"注意"];
                        }
                        
                        params.paramUrl = @"http://www.cpic.com.cn/cpic/index.shtml";
                        
                        if(![_tencentOAuth addShareWithParams:params]){
                            [self showInvalidTokenOrOpenIDMessage];
                        }
                    }
                    
                    if (isContent==YES && isImage==NO) {
                        TCAddShareDic *params = [TCAddShareDic dictionary];
                        params.paramTitle = @"太平洋保险-秒杀信息分享";
                        params.paramComment = @"我秒杀成功啦!";
                        strInsuranceTitle = [[NSString alloc] initWithFormat:@"我秒杀成功啦!!!以%@元秒杀到%@,天天有惊喜《车E服》http://www.cpic.com.cn/cx/sz/ydkhd/index.shtml",self.GoodsPrice,self.GoodsName];
                        params.paramSummary = strInsuranceTitle;
                        //            params.paramImages = @"http://img1.gtimg.com/tech/pics/hv1/95/153/847/55115285.jpg";
                        
                        params.paramUrl = @"http://www.cpic.com.cn/cpic/index.shtml";
                        
                        if(![_tencentOAuth addShareWithParams:params]){
                            [self showInvalidTokenOrOpenIDMessage];
                        }
                    }
                    
                }
            break;
            case 1008:
            if (buttonIndex == 1)
                {
                    TCAddShareDic *params = [TCAddShareDic dictionary];
                    params.paramTitle = @"太平洋保险-秒杀信息分享";
                    params.paramComment = @"我秒杀成功啦!";
                    strInsuranceTitle = [[NSString alloc] initWithFormat:@"我秒杀成功啦!!!以%@元秒杀到%@,天天有惊喜《车E服》http://www.cpic.com.cn/cx/sz/ydkhd/index.shtml",self.GoodsPrice,self.GoodsName];
                    params.paramSummary = strInsuranceTitle;
                    //            params.paramImages = @"http://img1.gtimg.com/tech/pics/hv1/95/153/847/55115285.jpg";
                    
                    params.paramUrl = @"http://www.cpic.com.cn/cpic/index.shtml";
                    
                    if(![_tencentOAuth addShareWithParams:params]){
                        [self showInvalidTokenOrOpenIDMessage];
                    }

                }
            break;
            default:
            break;
            }
}

#pragma UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView==TableViewGoodsInfo)
    {
        return [arrGoods count];
    }
    else
    {
        return [arrCustomer count];
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary * DictCustomerInfo =[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CUSTOMER_INFO];
    if (DictCustomerInfo!=nil) 
    {
        
//        if ([DictCustomerInfo valueForKey:@"userName"])
//        {
//            NSLog(@"%@",[DictCustomerInfo valueForKey:@"userName"]);
//        }
//        else 
//        {
//            [self justShowMessage:@"请到客户资料管理填写客户名称!" title:@"提示"];
//        }
//        
//        if ([DictCustomerInfo valueForKey:@"phone"])
//        {
//            NSLog(@"%@",[DictCustomerInfo valueForKey:@"phone"]);
//        }
//        else 
//        {
//            [self justShowMessage:@"请到客户资料管理填写手机号码!" title:@"提示"];
//        }
//        
//        if ([DictCustomerInfo valueForKey:@"postalAddress"])
//        {
//            NSLog(@"%@",[DictCustomerInfo valueForKey:@"postalAddress"]);
//        }
//        else 
//        {
//            [self justShowMessage:@"请到客户资料管理填写联系地址!" title:@"提示"];
//        }
    }
    else
    {
        [self justShowMessage:@"用户还没补充完整客户名称、手机号码、联系地址!" title:@"注意"];
    }
    
    if(tableView==TableViewGoodsInfo)
    {
        static NSString *Identifier=@"Identifier";
        UITableViewCell *cell=(UITableViewCell *)[TableViewGoodsInfo dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;//选中后颜色没变化
            
            if(indexPath.row==0)
            {
                UILabel *lblGoodsName=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 100, 21)];
                lblGoodsName.backgroundColor=[UIColor clearColor];
                lblGoodsName.text=[arrGoods objectAtIndex:indexPath.row];
                lblGoodsName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblGoodsName];
                [lblGoodsName release];
                
                txtGoodsName=[[UITextField alloc]initWithFrame:CGRectMake(125, 9.5, 170, 31)];
                txtGoodsName.borderStyle=UITextBorderStyleNone;
                txtGoodsName.enabled=NO;
                txtGoodsName.delegate = self;
                txtGoodsName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtGoodsName];
                txtGoodsName.placeholder = self.GoodsName;
            }
            else if(indexPath.row==1)
            {
                UILabel *lblGoodsSeckillTime=[[UILabel alloc]initWithFrame:CGRectMake(15,9.5, 110, 21)];
                lblGoodsSeckillTime.backgroundColor=[UIColor clearColor];
                lblGoodsSeckillTime.text=[arrGoods objectAtIndex:indexPath.row];
                lblGoodsSeckillTime.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblGoodsSeckillTime];
                [lblGoodsSeckillTime release];
                
                txtGoodsSeckillTime=[[UITextField alloc]initWithFrame:CGRectMake(125, 9.5, 170, 31)];
                txtGoodsSeckillTime.borderStyle=UITextBorderStyleNone;
                txtGoodsSeckillTime.delegate = self;
                txtGoodsSeckillTime.enabled=NO;
                txtGoodsSeckillTime.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtGoodsSeckillTime];
                txtGoodsSeckillTime.placeholder = self.GoodsSeckillTime;
            }
            else if(indexPath.row==2)
            {
                UILabel *lblPrice=[[UILabel alloc]initWithFrame:CGRectMake(15,9.5, 120, 21)];
                lblPrice.backgroundColor=[UIColor clearColor];
                lblPrice.text=[arrGoods objectAtIndex:indexPath.row];
                lblPrice.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblPrice];
                [lblPrice release];
                
                UITextField *txtPrice=[[UITextField alloc]initWithFrame:CGRectMake(138, 4.5, 170, 31)];
                txtPrice.borderStyle=UITextBorderStyleNone;
                txtPrice.returnKeyType = UIReturnKeyDone;
                txtPrice.delegate = self;
                txtPrice.enabled=NO;
                txtPrice.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtPrice];
                txtPrice.placeholder = self.GoodsPrice;
                //txtPrice.text = [DictCustomerInfo valueForKey:@"phone"];
            }
            else if(indexPath.row==3)
            {
                UILabel *lblSmsIdentifyingInfo=[[UILabel alloc]initWithFrame:CGRectMake(15,9.5, 120, 21)];
                lblSmsIdentifyingInfo.backgroundColor=[UIColor clearColor];
                lblSmsIdentifyingInfo.text=[arrGoods objectAtIndex:indexPath.row];
                lblSmsIdentifyingInfo.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblSmsIdentifyingInfo];
                [lblSmsIdentifyingInfo release];
                
                txtSmsIdentifyingInfo=[[UITextField alloc]initWithFrame:CGRectMake(138, 4.5, 170, 31)];
                txtSmsIdentifyingInfo.borderStyle=UITextBorderStyleLine;
                txtSmsIdentifyingInfo.returnKeyType = UIReturnKeyDone;
                CustomNumbleKeyboardView *customKeyboardView = [[CustomNumbleKeyboardView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 238)];
                customKeyboardView.delegate = self;
                [txtSmsIdentifyingInfo setInputView:customKeyboardView];
                txtSmsIdentifyingInfo.delegate = self;
                txtSmsIdentifyingInfo.enabled=YES;
                txtSmsIdentifyingInfo.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtSmsIdentifyingInfo];
                txtSmsIdentifyingInfo.placeholder = self.SmsIdentifyingInfo;
                txtSmsIdentifyingInfo.text = [DictCustomerInfo valueForKey:@"phone"];
            }

        }
        return cell;
    }
    else
    {
        static NSString *Identifier=@"Identifier";
        UITableViewCell *cell=(UITableViewCell *)[TableViewCustomerInfo dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
            if(indexPath.row==0)
            {
                UILabel *lblCustomerName=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 116, 21)];
                lblCustomerName.backgroundColor=[UIColor clearColor];
                lblCustomerName.text=[arrCustomer objectAtIndex:indexPath.row];
                lblCustomerName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblCustomerName];
                [lblCustomerName release];
                
                txtCustomerName=[[UITextField alloc]initWithFrame:CGRectMake(85, 4.5, 148, 31)];
                txtCustomerName.borderStyle=UITextBorderStyleLine;
                txtCustomerName.returnKeyType=UIReturnKeyDone;
                txtCustomerName.delegate=self;
                txtCustomerName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtCustomerName];
                txtCustomerName.text = [DictCustomerInfo valueForKey:@"userName"];
            }
            else if(indexPath.row==1)
            {
                UILabel *lblCustomerPhone=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 119, 21)];
                lblCustomerPhone.backgroundColor=[UIColor clearColor];
                lblCustomerPhone.text=[arrCustomer objectAtIndex:indexPath.row];
                lblCustomerPhone.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblCustomerPhone];
                [lblCustomerPhone release];
                
                txtCustomerPhone=[[UITextField alloc]initWithFrame:CGRectMake(85, 4.5, 148, 31)];
                txtCustomerPhone.borderStyle=UITextBorderStyleLine;
                txtCustomerPhone.returnKeyType=UIReturnKeyDone;
                txtCustomerPhone.delegate=self;
                txtCustomerPhone.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtCustomerPhone];
                txtCustomerPhone.text = [DictCustomerInfo valueForKey:@"phone"];
            }
            else if(indexPath.row==2)
            {
                UILabel *lblCustomerAddress=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 120, 21)];
                lblCustomerAddress.backgroundColor=[UIColor clearColor];
                lblCustomerAddress.text=[arrCustomer objectAtIndex:indexPath.row];
                lblCustomerAddress.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblCustomerAddress];
                [lblCustomerAddress release];
                
                txtCustomerAddress=[[UITextField alloc]initWithFrame:CGRectMake(85, 4.5, 218, 31)];
                txtCustomerAddress.borderStyle=UITextBorderStyleLine;
                txtCustomerAddress.returnKeyType=UIReturnKeyDone;
                txtCustomerAddress.delegate =self;
                txtCustomerAddress.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtCustomerAddress];
                 txtCustomerAddress.text = [DictCustomerInfo valueForKey:@"postalAddress"];
            }
        }
        return cell;
    }
    
}

//数字键盘
- (void)numberKeyBoardInput:(NSInteger) number
{
    NSMutableString *textString = [[[NSMutableString alloc] initWithFormat:@"%@%d",txtSmsIdentifyingInfo.text,number] autorelease];
    if ([textString length]>11)
    {
        [self justShowMessage:@"手机号码输入不能超过11位!" title:@""];
        return;
    }
    txtSmsIdentifyingInfo.text = textString;
}

- (void)numberKeyBoardBackspace
{
    NSMutableString* mutableString = [[[NSMutableString alloc] initWithFormat:@"%@", txtSmsIdentifyingInfo.text] autorelease];
    if ([mutableString length] >=1) {
        NSRange tmpRange;
        tmpRange.location = [mutableString length] - 1;
        tmpRange.length = 1;
        [mutableString deleteCharactersInRange:tmpRange];
    }
    txtSmsIdentifyingInfo.text = mutableString;
    
}

- (void)numberKeyBoardFinish
{
    [txtSmsIdentifyingInfo resignFirstResponder];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

-(void)setSeckillConfirmRequest//向太保移动平台发送秒杀提交确认请求报文
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
//        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
//        return;
    }
    
    NSString * useraccount;
    if ([dictUserInfo valueForKey:@"UserAccount"]) {
        useraccount = [dictUserInfo valueForKey:@"UserAccount"];
    }
    else
    {
        useraccount=@"cpic";
    }
//    NSString *strRequestCode=@"RequestCode=50403";
    NSString *strRequestData=[NSString stringWithFormat:@"{\"CommodityID\":\"%@\",\"UserAccount\":\"%@\",\"CommodityName\":\"%@\",\"SecKillTime\":\"%@\",\"MessReceive\":\"%@\",\"ContactPhone\":\"%@\",\"ContactAddress\":\"%@\"}",CommodityId,useraccount,self.GoodsName,self.GoodsSeckillTime,txtSmsIdentifyingInfo.text,txtCustomerPhone.text,txtCustomerAddress.text];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,strRequestCode,strRequestData];
//    NSLog(@"++++++++++++++%@",strUrl);
//    strUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    
//    NSURL *myurl = [NSURL URLWithString:strUrl];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"URL:%@",myurl);
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"50403" forKey:@"RequestCode"];
    [request setPostValue:strRequestData forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseFail:)];
    [request setDidFinishSelector:@selector(ResonseSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    if ([ss isEqualToString:@"1"])
    {
        NSString *strMessage=[[NSString alloc]initWithFormat:@"恭喜你秒中产品成功,流水号%@,请您于30分钟内确认收货!",[dictResponse objectForKey:@"orderID"]];
        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:strMessage delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"分享到新浪微博",@"分享到腾讯微博",nil];
        alertView.tag=111;
        [alertView show];
        [alertView release];
        [strMessage release];
    }
    else
    {
        NSString *strMessage=[jsonoSubObj objectForKey:@"message"];
        [self justShowMessage:strMessage title:@"注意"];
        //[self justShowMessage:@"秒杀提交确认失败！" title:@"提示"];
    }
    
    NSString *commodityID = [dictResponse objectForKey:@"commodityID"];
    NSString *orderID = [dictResponse objectForKey:@"orderID"];
    NSString *userAccount = [dictResponse objectForKey:@"userAccount"];
    NSLog(@"-----------%@",commodityID);
    NSLog(@"-----------%@",orderID);
    NSLog(@"-----------%@",userAccount);
    
    NSString *Code =@"60601";
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString * serialNostr=[accountDefaults objectForKey:@"OPERATIONLOG"]; 
    OperationLogView *operationlog =[[OperationLogView alloc]initView:Code withtype:@"2" withserialno:serialNostr];
    [operationlog setOperationLogRequest];
    [operationlog setHidden:YES];
    [self.view addSubview:operationlog];
    [operationlog release];
}

- (void)ResponseFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败！" title:@"提示"];
}

-(id)initView:(NSMutableDictionary *)SeckillInfo
{
    self.seckillInfo = SeckillInfo;
    self = [super init];
    return self;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if(textField==txtCustomerName||textField == txtCustomerPhone ||textField==txtCustomerAddress)
    {
        [self SetAnimation:80];
    }
    
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if(textField==txtCustomerName||textField == txtCustomerPhone ||textField==txtCustomerAddress)
    {
        [self backAnimation:80];
    }
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if(textField==txtSmsIdentifyingInfo)
    {
        if(range.location>=11)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtCustomerName)
    {
        if(range.location>=10)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtCustomerPhone)
    {
        if(range.location>=11)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtCustomerAddress)
    {
        if(range.location>=30)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    return YES;
}

-(void)SetAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x+=Xorigin;
    frame.origin.y-=Xorigin;
    //frame.size.height +=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
}

-(void)backAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x -=Xorigin;
    frame.origin.y+=Xorigin;
    //frame.size.height -=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
    // [textField resignFirstResponder];
}

/*手机号码验证*/
-(BOOL) isValidateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}

-(void)caculateShareIntegral
{
    RCCaculateIntegral *rcCaculateIntegral=[[RCCaculateIntegral alloc]initCaculateIntegalView];
    [rcCaculateIntegral setCaculatRequest:@"61002"];
    [rcCaculateIntegral setHidden:YES];
    [self.view addSubview:rcCaculateIntegral];
    [rcCaculateIntegral release];
}

static int post_image_status_times = 0;
static int post_status_times = 0;
-(void)shareSina
{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    myDelegate.bKnowledgeInsurance=TRUE;
    
    AppDelegate *appMyDelegate=[[UIApplication sharedApplication]delegate];
    appMyDelegate.iLoginorAccountTag=1;
    
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    NSLog(@"%@", [keyWindow subviews]);
    
    
    SinaWeibo *sinaweibo = [self sinaweibo];
    
    if ([sinaweibo isAuthValid]) {
        //[self justShowMessage:@"你已经授权新浪微博" title:@"提示"];
        if (isImage==YES && isContent==NO) {
            if (!postImageStatusText)
            {
                post_image_status_times ++;
                [postImageStatusText release], postImageStatusText = nil;
                //postImageStatusText = [[NSString alloc] initWithFormat:@"CPICApp image status : %i %@", post_image_status_times, [NSDate date]];
                postImageStatusText = [[NSString alloc] initWithFormat:@"我秒杀成功啦!!!以%@元秒杀到%@,天天有惊喜《车E服》http://www.cpic.com.cn/cx/sz/ydkhd/index.shtml",self.GoodsPrice,self.GoodsName];
            }
            
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                message:[NSString stringWithFormat:@"你将分享以上内容到新浪微博 \"%@\"", postImageStatusText]
                                                               delegate:self cancelButtonTitle:@"Cancel"
                                                      otherButtonTitles:@"OK", nil];
            alertView.tag = 1005;
            [alertView show];
            [alertView release];
        }
        else if(isImage==NO && isContent==YES)
        {
            if (!postStatusText)
            {
                post_status_times ++;
                [postStatusText release], postStatusText = nil;
                //postStatusText = [[NSString alloc] initWithFormat:@"CPICApp text status : %i %@%@", post_status_times, [NSDate date],strShareContent];
                postStatusText = [[NSString alloc] initWithFormat:@"我秒杀成功啦!!!以%@元秒杀到%@,天天有惊喜《车E服》http://www.cpic.com.cn/cx/sz/ydkhd/index.shtml",self.GoodsPrice,self.GoodsName];
            }
            
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                                message:[NSString stringWithFormat:@"你将分享以上内容到新浪微博 \"%@\"", postStatusText]
                                                               delegate:self cancelButtonTitle:@"Cancel"
                                                      otherButtonTitles:@"OK", nil];
            alertView.tag = 1006;
            [alertView show];
            [alertView release];
        }
        
    }
    else
    {
        [sinaweibo logIn];
    }
    
}
//- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
//{
//    if (buttonIndex == 1)
//    {
//        if (alertView.tag == 0)
//        {
//            // post status
//            NSLog(@"保险知识%@",postStatusText);
//            SinaWeibo *sinaweibo = [self sinaweibo];
//            [sinaweibo requestWithURL:@"statuses/update.json"
//                               params:[NSMutableDictionary dictionaryWithObjectsAndKeys:
//                                       postStatusText, @"status",
//                                       nil]
//                           httpMethod:@"POST"
//                             delegate:self];
//            
//        }
//        else if (alertView.tag == 1)
//        {
//            // post image status
//            
//            SinaWeibo *sinaweibo = [self sinaweibo];
//            
//            [sinaweibo requestWithURL:@"statuses/upload.json"
//                               params:[NSMutableDictionary dictionaryWithObjectsAndKeys:
//                                       postImageStatusText, @"status",
//                                       imageDown, @"pic", nil]
//                           httpMethod:@"POST"
//                             delegate:self];
//            
//        }
//        else if(alertView.tag==2)
//        {
//            if (isImage==YES && isContent==NO) {
//                TCAddShareDic *params = [TCAddShareDic dictionary];
//                params.paramTitle = @"太平洋保险- 秒杀信息分享";
//                params.paramComment = strInsuranceTitle;
//                //            params.paramSummary =  @"中国太平洋保险成立于1991年5月13日，总部设在上海，成功在A股和H股上市，旗下拥有太平洋寿险、太平洋产险、太平洋资产管理公司和长江养老保险等专业子公司，保持持续领先的市场地位。";
//                //            params.paramImages = @"http://img1.gtimg.com/tech/pics/hv1/95/153/847/55115285.jpg";
//                
//                if ([ImgUrl isKindOfClass:[NSString class]]==YES) {
//                    if (ImgUrl.length!=0) {
//                        params.paramImages=ImgUrl;
//                    }
//                }
//                else
//                {
//                    [self justShowMessage:@"图片地址无效" title:@"注意"];
//                }
//                
//                params.paramUrl = @"http://www.cpic.com.cn/cpic/index.shtml";
//                
//                if(![_tencentOAuth addShareWithParams:params]){
//                    [self showInvalidTokenOrOpenIDMessage];
//                }
//            }
//            
//            if (isContent==YES && isImage==NO) {
//                TCAddShareDic *params = [TCAddShareDic dictionary];
//                params.paramTitle = @"太平洋保险-秒杀信息分享";
//                params.paramComment = strInsuranceTitle;
//                params.paramSummary = strShareContent;
//                //            params.paramImages = @"http://img1.gtimg.com/tech/pics/hv1/95/153/847/55115285.jpg";
//                
//                params.paramUrl = @"http://www.cpic.com.cn/cpic/index.shtml";
//                
//                if(![_tencentOAuth addShareWithParams:params]){
//                    [self showInvalidTokenOrOpenIDMessage];
//                }
//            }
//            
//        }
//        else if(alertView.tag==3)
//        {
//            TCAddShareDic *params = [TCAddShareDic dictionary];
//            params.paramTitle = @"太平洋保险-秒杀信息分享";
//            params.paramComment = strInsuranceTitle;
//            params.paramSummary = strShareContent;
//            //            params.paramImages = @"http://img1.gtimg.com/tech/pics/hv1/95/153/847/55115285.jpg";
//            
//            params.paramUrl = @"http://www.cpic.com.cn/cpic/index.shtml";
//            
//            if(![_tencentOAuth addShareWithParams:params]){
//                [self showInvalidTokenOrOpenIDMessage];
//            }
//        }
//    }
//    else if(buttonIndex==0)
//    {
//        if (alertView.tag==1004) {
//            [self setSeckillConfirmRequest];
//        }
//    }
//}
- (void)showInvalidTokenOrOpenIDMessage{
    UIAlertView *alert = [[[UIAlertView alloc]initWithTitle:@"api调用失败" message:@"可能授权已过期，请重新获取" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];
    [alert show];
}
/**
 * Called when the add_share has response.
 */
- (void)addShareResponse:(APIResponse*) response {
	if (response.retCode == URLREQUEST_SUCCEED)
	{
		
		[self caculateShareIntegral];
		NSMutableString *str=[NSMutableString stringWithFormat:@""];
		for (id key in response.jsonResponse) {
			[str appendString: [NSString stringWithFormat:@"%@:%@\n",key,[response.jsonResponse objectForKey:key]]];
		}
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"操作成功" message:nil
							  
													   delegate:self cancelButtonTitle:@"我知道啦" otherButtonTitles:nil];
		[alert show];
        [alert release];
		
		
		
	}
	else {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"操作失败" message:[NSString stringWithFormat:@"%@", response.errorMsg]
							  
													   delegate:self cancelButtonTitle:@"我知道啦" otherButtonTitles: nil];
		[alert show];
        [alert release];
	}
}

-(void)shareQQ
{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    myDelegate.bKnowledgeInsurance=TRUE;
    
    if([_tencentOAuth isSessionValid])
    {
        if (isImage==YES && isContent==NO) {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"你将分享以上内容到腾讯微博" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            alert.tag=1007;
            [alert show];
            [alert release];
        }
        else if(isContent==YES && isImage==NO)
        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"你将分享以上内容到腾讯微博" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            alert.tag=1008;
            [alert show];
            [alert release];
        }
        
    }
    else
    {
        [_tencentOAuth authorize:_permissions inSafari:NO];
    }
    
}

-(void)setBindCheckRequest//向太保移动平台发送请求报文
{
    //    NSString *strRequestCode=@"RequestCode=62102";
    NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
    if (QQopenId.length!=0) {
        [dicRequest setValue:QQopenId forKey:@"UserId"];
    }
    else
    {
        [dicRequest setValue:@"" forKey:@"UserId"];
    }
    [dicRequest setValue:@"2" forKey:@"bindingType"];
    NSString *strRequestJson=[dicRequest JSONRepresentation];
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"62102" forKey:@"RequestCode"];
    [request setPostValue:strRequestJson forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseBindCheckFail:)];
    [request setDidFinishSelector:@selector(ResonseBindCheckSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress) {
        NSLog(@"88888");
        // [NSThread sleepForTimeInterval:1];
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"查询中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseBindCheckSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictHead=[dictResponse valueForKey:@"head"];
    NSString *strResult= [[NSString alloc] initWithFormat:@"%@",[dictHead objectForKey:@"success"]];
    NSLog(@"strResult%@",strResult);
    NSString *strUserAccount1=[dictResponse objectForKey:@"userAccount"];
    // if ([strResult isEqualToString:@"1"]) {
    if (strUserAccount1.length!=0) {
        //[self justShowMessage:@"登录成功" title:nil];
        bindingQQ=YES;
        [self checkQQAuth];
    }
    else
    {
        //[self justShowMessage:@"登录失败" title:nil];
        bindingQQ=NO;
        [self checkQQAuth];
        
    }
    
}
-(void)checkQQAuth
{
    if([_tencentOAuth isSessionValid])
    {
        if (bindingQQ==NO) {
            [self justShowMessage:@"你还没绑定本系统账户,请到绑定页面进行绑定" title:@"确定"];
        }
//        else
//        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"你将分享以上内容到腾讯微博" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            alert.tag=2;
            [alert show];
            [alert release];
//        }
    }
    else
    {
        [_tencentOAuth authorize:_permissions inSafari:NO];
    }
    
    
}

- (void)ResponseBindCheckFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}


- (SinaWeibo *)sinaweibo
{
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    return delegate.sinaweibo;
}
- (void)storeAuthData
{
    SinaWeibo *sinaweibo = [self sinaweibo];
    
    NSDictionary *authData = [NSDictionary dictionaryWithObjectsAndKeys:
                              sinaweibo.accessToken, @"AccessTokenKey",
                              sinaweibo.expirationDate, @"ExpirationDateKey",
                              sinaweibo.userID, @"UserIDKey",
                              sinaweibo.refreshToken, @"refresh_token", nil];
    [[NSUserDefaults standardUserDefaults] setObject:authData forKey:@"SinaWeiboAuthData"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [self justShowMessage:@"授权成功" title:nil];
}
#pragma mark - SinaWeibo Delegate

- (void)sinaweiboDidLogIn:(SinaWeibo *)sinaweibo
{
    NSLog(@"sinaweiboDidLogIn userID = %@ accesstoken = %@ expirationDate = %@ refresh_token = %@", sinaweibo.userID, sinaweibo.accessToken, sinaweibo.expirationDate,sinaweibo.refreshToken);
    [self storeAuthData];
}

- (void)sinaweiboDidLogOut:(SinaWeibo *)sinaweibo
{
    NSLog(@"sinaweiboDidLogOut");
    
}

- (void)sinaweiboLogInDidCancel:(SinaWeibo *)sinaweibo
{
    NSLog(@"sinaweiboLogInDidCancel");
}

- (void)sinaweibo:(SinaWeibo *)sinaweibo logInDidFailWithError:(NSError *)error
{
    NSLog(@"sinaweibo logInDidFailWithError %@", error);
}

- (void)sinaweibo:(SinaWeibo *)sinaweibo accessTokenInvalidOrExpired:(NSError *)error
{
    NSLog(@"sinaweiboAccessTokenInvalidOrExpired %@", error);
    
}

#pragma mark - SinaWeiboRequest Delegate

- (void)request:(SinaWeiboRequest *)request didFailWithError:(NSError *)error
{
    if ([request.url hasSuffix:@"users/show.json"])
    {
        [userInfo release], userInfo = nil;
    }
    else if ([request.url hasSuffix:@"statuses/user_timeline.json"])
    {
        [statuses release], statuses = nil;
    }
    else if ([request.url hasSuffix:@"statuses/update.json"])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                            message:[NSString stringWithFormat:@"Post status \"%@\" failed!", postStatusText]
                                                           delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alertView show];
        [alertView release];
        
        NSLog(@"Post status failed with error : %@", error);
    }
    else if ([request.url hasSuffix:@"statuses/upload.json"])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                            message:[NSString stringWithFormat:@"Post image status \"%@\" failed!", postImageStatusText]
                                                           delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alertView show];
        [alertView release];
        
        NSLog(@"Post image status failed with error : %@", error);
    }
    
    
    
}

- (void)request:(SinaWeiboRequest *)request didFinishLoadingWithResult:(id)result
{
    [self caculateShareIntegral];
    if ([request.url hasSuffix:@"users/show.json"])
    {
        [userInfo release];
        userInfo = [result retain];
    }
    else if ([request.url hasSuffix:@"statuses/user_timeline.json"])
    {
        [statuses release];
        statuses = [[result objectForKey:@"statuses"] retain];
    }
    else if ([request.url hasSuffix:@"statuses/update.json"])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                            message:@"分享成功"
                                                           delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alertView show];
        [alertView release];
        
        [postStatusText release], postStatusText = nil;
    }
    else if ([request.url hasSuffix:@"statuses/upload.json"])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                            message:@"分享成功"
                                                           delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alertView show];
        [alertView release];
        
        [postImageStatusText release], postImageStatusText = nil;
    }
    
}
- (void)storeAuthQQ
{
    
    NSDictionary *authData = [NSDictionary dictionaryWithObjectsAndKeys:
                              QQAccessToken, @"QQAccessToken",
                              QQopenId, @"QQopenId", nil];
    
    [[NSUserDefaults standardUserDefaults] setObject:authData forKey:@"Dict_QQAuthData"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
#pragma mark - TencentSessionDelegate
/**
 * Called when the user successfully logged in.
 */
- (void)tencentDidLogin {
	// 登录成功
	[self justShowMessage:@"QQ登录成功" title:nil];
    
    
    if (_tencentOAuth.accessToken
        && 0 != [_tencentOAuth.accessToken length])
    {
        QQAccessToken = _tencentOAuth.accessToken;
        QQopenId=_tencentOAuth.openId;
        [self storeAuthQQ];
        [self setBindCheckRequest];
    }
    else
    {
        QQAccessToken = @"登录不成功 没有获取accesstoken";
    }
    
}

/**
 * Called when the user dismissed the dialog without logging in.
 */
- (void)tencentDidNotLogin:(BOOL)cancelled
{
	if (cancelled){
        [self justShowMessage:@"用户取消登录" title:nil];
	}
	else {
        [self justShowMessage:@"登录失败" title:nil];
	}
	
}
/**
 * Called when the notNewWork.
 */
-(void)tencentDidNotNetWork
{
    [self justShowMessage:@"无网络连接，请设置网络" title:nil];
}

/**
 * Called when the logout.
 */
-(void)tencentDidLogout
{
    [self justShowMessage:@"退出登录成功，请重新登录" title:nil];
    QQAccessToken = @"";
    
    
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    [TableViewCustomerInfo release];
    [TableViewGoodsInfo release];
    [txtGoodsSeckillTime release];
    [txtGoodsName release];
    [txtSmsIdentifyingInfo release];
    [txtCustomerName release];
    [txtCustomerPhone release];
    [txtCustomerAddress release];
    [CustomerPhone release];
    [CustomerAddress release];
    [CustomerName release];
    [GoodsName release];
    [GoodsSeckillTime release];
    [SmsIdentifyingInfo release];
    [progress release];
    [seckillInfo release];
    [SeckillSuccessTime release];
    [GoodsPrice release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
